import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import mangePark from './modules/mangePark'
import mocs from './modules/mocs'
import ieceSwing from './modules/ieceSwing'
import condoFee from './modules/condoFee'
import system from './modules/system'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    path: '/',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: '',
        component: () => import('@/views/dashboard'),
        meta: {
          title: '工作台',
          icon: '电脑_o'
        }
      }

    ]
  },
  {
    path: '/monthCard/addMonthCard',
    name: 'addMonthCard',
    component: () => import('@/views/mocs/components/monthCard/addMonthCard.vue'),
    hidden: true

  },
  {
    path: '/monthCard/renewalCard/:id?',
    name: 'renewalCard',
    component: () => import('@/views/mocs/components/monthCard/renewalCard.vue'),
    hidden: true

  },
  {
    path: '/monthCard/examineCard/:id?',
    name: 'examineCard',
    component: () => import('@/views/mocs/components/monthCard/examineCard.vue'),
    hidden: true

  },
  {
    path: '/monthCard/redactCard/:id?',
    name: 'redactCard',
    component: () => import('@/views/mocs/components/monthCard/redactCard.vue'),
    hidden: true

  },
  {
    path: '/enterprise/addEnt',
    name: 'addEnt',
    component: () => import('@/views/enterprise/addEnt.vue'),
    hidden: true

  },
  mangePark,
  mocs,
  condoFee,
  ieceSwing,
  system,

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
